
class Widget implements Comparable {
     String   name
     Person   owner
     String   description
     String   widgetUrl


     Date dateCreated = new Date()
     Date lastUpdated = new Date()

     static belongsTo = [ Person ]

     static mapping = {
	   name index: 'widget_index', unique: true
     }

     static constraints = {
	   name(size: 1..40, blank: false, unique: true)
	   // Size limitation on  description dropped (for now)
     }


   // XXX This is the wrong way to do it.  The best way to do this
   //     would be to make a MarkupBuilder that can generate
   //     parameterized iwg files, like groovy.xml.Markupbuilder (see http://www.ociweb.com/javasig/knowledgebase/2006-12/GroovyIntro.pdf)
   //     XXX The "name"  thingy should be as it is, but, should have double quotes quoted inside of it in some way.
   //         or perhaps we should just forbid the use of quotes in names? Hm, I think so.  Add more constraints!

 public String toControlIwgXml() {

return 
"""<?xml version="1.0" encoding="windows-1252"?>
<widgetcontrol ver="0.2" id="widgary">
  <command type="storeaddentity" list="widgetlist" etype="widgetdef">
     <attribute id="name" value="${name}" />
     <attribute id="widgetiwg" value="${widgetUrl}" />
     <attribute id="infourl"   value="/widgets/info/${id}" />
  </command>
  <command type="showtab" view="widgerymain" tab="panel1" />
</widgetcontrol>
""";

 }

     int compareTo(obj) {
        obj.id.compareTo(id)
    }


}
